<template xmlns="http://www.w3.org/1999/html">
  <sea-data-table ref="tableObject" url="/sys/dic/config/page">
    <!--表头-->
    <sea-table-header slot="header" disabled-form>
      <!--标题栏-->
      <sea-table-title slot="title" title="数据字典" subtitle="说实话，直接改数据库更快"></sea-table-title>

      <!--按钮栏-->
      <template slot="buttons">
        <el-button plain size="small" title="Excel导入" icon="fa fa-upload" @click="onAction('import')"></el-button>
        <el-button plain size="small" title="新增" icon="fa fa-plus" @click="onAction('new')"></el-button>
      </template>
    </sea-table-header>

    <!--表头-->
    <template slot="columns">
      <sea-col-input property="id" label="ID" width="100" :change="onAction"></sea-col-input>
      <el-table-column property="schemaName" label="数据库名" width="180"></el-table-column>
      <el-table-column property="tableName" label="表名" width="200"></el-table-column>
      <el-table-column property="columnName" label="列名" width="200"></el-table-column>
      <sea-col-input property="columnAlias" label="字段名" width="200" :change="onAction"></sea-col-input>
      <sea-col-input property="defaultStyle" label="默认样式" :change="onAction"></sea-col-input>

      <!--操作栏-->
      <sea-table-actionbar width="180" :on-action="onAction" :buttons="buttons"></sea-table-actionbar>
    </template>

    <!-- 弹窗、抽屉 -->
    <template slot="drawer">
      <sea-dialog ref="create_dialog">
        <create ref="create"></create>
      </sea-dialog>
      <sea-dialog ref="modify_dialog">
        <item ref="modify" :object="row_data"></item>
      </sea-dialog>
    </template>
  </sea-data-table>
</template>

<script>
import create from "./create";
import item from "./item";

export default {
    components: {
        create, item
    },
    data() {
        return {
            // 操作名称
            operation: undefined
            // 当前操作的行级对象
            , row_data: undefined
            // 操作栏
            , buttons: [
                {type: 'btn', evt: 'del', label: '删除', title: '删除数据字典'}
                , {type: 'btn', evt: 'dic', label: '字典明细', title: '编辑数据字典'}
            ]
            // end--
        }
    },
    methods: {
        /**
         * 操作成功回调
         */
        onSucceed: function () {
            this.$refs.tableObject.reload();
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            if (evt === 'new') {
                let dialog = {title: `新建`};
                this.$refs.create_dialog.open(dialog);
            } else if (evt === 'dic') {
                let dialog = {title: `管理键值`, width: '50%', fullscreen: true};
                this.$refs.modify_dialog.open(dialog).then(() => this.row_data = row);
            } else if (evt === 'del') {
                this.$layers.ajax({
                    method: "DELETE",
                    url: 'sys/dic/config/info',
                    params: row
                }).then(result => {
                    if (result.code === 0) {
                        this.$layers.succeed();
                        this.$refs.tableObject.reload();
                    }
                });
            } else if (evt === 'import') {
                Layers.warn('功能建设中！');
            } else if (evt === '$edit') {
                this.$layers.ajax({
                    method: "PUT",
                    url: 'sys/dic/config/info',
                    params: row
                }).then(result => {
                    if (result.code === 0) {
                        this.$layers.succeed();
                    }
                });
            } else {
            }
        }
    }
}
</script>
